package com.example.kotlinstudy

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.kotlinstudy.adapter.ColorAdapter

class ViewPager2Activity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_view_pager2)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        // 将 ColorAdapter 应用
        findViewById<androidx.viewpager2.widget.ViewPager2>(R.id.viewPager2).adapter =
            ColorAdapter()

        // 给 ViewPage2的每一项绑定点击事件，点击之后弹出 点了xxx
//        findViewById<androidx.viewpager2.widget.ViewPager2>(R.id.viewPager2).setPageTransformer { page, position ->
//            page.setOnClickListener {
//                // tag拿不到，我希望输出索引
//                val index = page.tag as Int
//                Toast.makeText(this, "点击了第${index}项", Toast.LENGTH_SHORT).show()
//            }
//        }
    }
}